package com.wlyuan.index.controller;

import com.alibaba.fastjson.JSONObject;
import com.wlyuan.index.api.IWaybillIndexService;
import com.wlyuan.index.api.dto.waybill.WaybillIndexFilterDTO;
import com.wlyuan.index.api.dto.waybill.WaybillReindexAllDTO;
import com.wlyuan.index.api.dto.waybill.WaybillReindexDTO;
import com.wlyuan.index.api.vo.WaybillIndexSumVO;
import com.wlyuan.index.api.vo.WaybillIndexVO;
import com.wlyuan.tools.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

/**
 * @author yuanjie
 */
@Slf4j
@Api(tags = "运单")
@RestController
@RequestMapping("/waybill")
public class WaybillIndexController {
    @DubboReference(check = false)
    private IWaybillIndexService waybillIndexService;

    @ApiOperation("查询索引")
    @GetMapping("/{waybillId:\\d+}")
    public WaybillIndexVO getIndexById(@PathVariable("waybillId") Long waybillId) {
        return waybillIndexService.getIndexById(waybillId);
    }

    @ApiOperation("重建索引")
    @PostMapping("/reindex/{waybillId:\\d+}")
    public void reindex(@PathVariable("waybillId") Long waybillId) {
        waybillIndexService.reindex(waybillId);
    }

    @ApiOperation("重建索引(筛选)")
    @PostMapping("/reindex")
    public void reindex(@RequestBody WaybillReindexDTO reindex) {
        waybillIndexService.reindex(reindex);
    }

    @ApiOperation("重建索引(全部)")
    @PostMapping("/reindexAll")
    public void reindexAll(@RequestBody WaybillReindexAllDTO reindex) {
        waybillIndexService.reindexAll(reindex);
    }

    @ApiOperation("运单列表")
    @PostMapping("/search")
    public Page<?> search(@RequestBody WaybillIndexFilterDTO filter) {
        return waybillIndexService.search(filter);
    }

    @ApiOperation("运单统计")
    @PostMapping("/sum")
    public WaybillIndexSumVO searchSum(@RequestBody WaybillIndexFilterDTO filter) {
        return waybillIndexService.searchSum(filter);
    }

    @ApiOperation("索引数据")
    @GetMapping("/insight/{waybillId:\\d+}")
    public JSONObject insight(@PathVariable("waybillId") Long waybillId) {
        return waybillIndexService.insight(waybillId);
    }

    @ApiOperation("索引差异")
    @GetMapping("/diffs")
    public JSONObject diffs() {
        return waybillIndexService.diffs();
    }
}
